/*
 * @lc app=leetcode.cn id=125 lang=javascript
 *
 * [125] 验证回文串
 */

// @lc code=start
/**
 * @param {string} s
 * @return {boolean}
 */
var isPalindrome = function (s) {
  if (s.length == 0) return true;

  let res = true;
  const len = s.length;
  for (let i = 0, j = len - 1; i < j; ) {
    const leftChar = s[i];
    const rightChar = s[j];

    if (!isValidChar(leftChar)) {
      i++;
      continue;
    }
    if (!isValidChar(rightChar)) {
      j--;
      continue;
    }

    if (leftChar.toLowerCase() !== rightChar.toLowerCase()) {
      res = false;
      break;
    }

    i++;
    j--;
  }

  return res;
};

var isValidChar = function (char) {
  return RegExp(/[a-zA-Z0-9]/).test(char);
};
// @lc code=end
